﻿<Window x:Class="TestApplication.DatePickerTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="http://schemas.AvalonControls/AvalonControlsLibrary/Controls"
    Title="DateTimePickerTest"
    xmlns:current="clr-namespace:TestApplication">
    

    <Window.Resources>

        <!--Control template for date picker-->
        <ControlTemplate x:Key="DatepickerTemplate" TargetType="{x:Type local:DatePicker}">
            <Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:DatePicker}}}">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <DockPanel LastChildFill="True" Grid.Row="0">
                    <Button Content="Prev" Name="PART_MonthBack" DockPanel.Dock="Left"/>
                    <Button Content="Next" Name="PART_MonthForward" DockPanel.Dock="Right"/>
                    <TextBlock Text="Month: " Margin="35,0,0,0"/>
                    <TextBlock Text="{Binding CurrentlyViewedMonth}" />
                </DockPanel>
                <ComboBox Grid.Row="1" Name="PART_Dates" IsReadOnly="True" Text="{Binding CurrentlySelectedDate}">
                    <ComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Width="200" Height="130"/>
                        </ItemsPanelTemplate>
                    </ComboBox.ItemsPanel>
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="Silver" BorderThickness="1" Width="25">
                                <TextBlock Text="{Binding DayNumber}"/>
                            </Border>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <TextBlock Text="{TemplateBinding CurrentlySelectedDate}" Grid.Row="2" />
            </Grid>
        </ControlTemplate>
    </Window.Resources>

    <DockPanel LastChildFill="True">

        <TextBlock DockPanel.Dock="Top">
            <current:BrowserLink NavigateUri="http://marlongrech.wordpress.com/2007/09/11/wpf-datepicker/">For more info click here</current:BrowserLink>
        </TextBlock>

        <StackPanel>

			<TextBlock Text="Original DatePicker" FontWeight="Bold"/>
            <TextBlock Text="This also shows the MinDate and MaxDate feature" />
			<!--Date picker 1 (Original)-->
			<local:DatePicker Margin="0,10,0,0" Width="200" Name="datePicker" />
			<TextBlock Margin="0,10,0,0" Text="Current Selected Date"/>
			<TextBlock Text="{Binding ElementName=datePicker, Path=CurrentlySelectedDate}"/>
			
			<TextBlock Text="Using the styling features of DatePicker" FontWeight="Bold"/>
            
			<!--Date picker 1 (Using the styling features of DatePicker)-->
			<local:DatePicker Margin="0,10,0,0" Width="200" Name="restyledDatePicker">
                
                <!--Sets the Day Header template (this sets the template for the Sun, Mon etc...)-->
                <local:DatePicker.DayHeaderTemplate>
                    <DataTemplate>
                        <Border Background="Yellow">
                            <TextBlock Foreground="Lime" Text="{Binding}"/>
                        </Border>
                    </DataTemplate>
                </local:DatePicker.DayHeaderTemplate>
                
                <!--Sets the Day Cell template for the individual days in the list-->
                <local:DatePicker.DayCellTemplate>
                    <DataTemplate>
                        <Border Name="border">
                            <TextBlock Text="{Binding DayNumber}" Name="dayCell"/>
                        </Border>
                        <DataTemplate.Triggers>
                            <!--This trigger is to do some thing with the template when an item is selected-->
                            <DataTrigger Binding="{Binding RelativeSource={
                                                    RelativeSource AncestorType={x:Type ListBoxItem}}, 
                                                    Path=IsSelected}"
                                         Value="True">
                                <Setter Property="Background" Value="Blue" TargetName="border"/>
                            </DataTrigger>
                            <!--This is for those dates that fall out of the MinDate and MaxDate.-->
                            <DataTrigger Binding="{Binding IsEnabled}" Value="False">
                                <Setter Property="Background" Value="Gray" TargetName="border"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding IsInCurrentMonth}" Value="False">
                                <Setter Property="Foreground" Value="Gray" TargetName="dayCell"/>
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </local:DatePicker.DayCellTemplate>
                
                <!--Style for the Month left button-->
                <local:DatePicker.MonthBackButtonStyle>
                    <Style TargetType="Button">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border BorderBrush="Pink" Width="20" BorderThickness="2">
                                        <TextBlock Text="&lt;" FontWeight="Bold"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </local:DatePicker.MonthBackButtonStyle>
                
                <!--Style for the Month forward button-->
                <local:DatePicker.MonthForwardButtonStyle>
                    <Style TargetType="Button">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="Button">
                                    <Border BorderBrush="Pink" Width="20" BorderThickness="2">
                                        <TextBlock Text="&gt;" TextAlignment="Right" FontWeight="Bold"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </local:DatePicker.MonthForwardButtonStyle>
                
                <!--Style for the month selector drop down-->
                <local:DatePicker.MonthSelectorStyle>
                    <Style TargetType="ComboBox">
                        <Setter Property="Background" Value="Yellow"/>
                        <Setter Property="ItemContainerStyle">
                            <Setter.Value>
                                <Style TargetType="ComboBoxItem">
                                    <Setter Property="Background" Value="Yellow"/>
                                </Style>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="ItemTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <TextBlock Foreground="Red" Text="{Binding}"/>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </local:DatePicker.MonthSelectorStyle>
                
            </local:DatePicker>
            
			<TextBlock Margin="0,10,0,0" Text="Current Selected Date"/>
			<TextBlock Text="{Binding ElementName=restyledDatePicker, Path=CurrentlySelectedDate}"/>
	        
			<!--Date picker 2 (with a simple control template)-->
			<TextBlock Text="Custom Templated DatePicker" FontWeight="Bold" Margin="0,30,0,0"/>
			<local:DatePicker Width="200" Margin="0,10,0,0" Name="datePicker2" Template="{StaticResource DatepickerTemplate}"/>
			<TextBlock Margin="0,10,0,0" Text="Current Selected Date"/>
			<TextBlock Text="{Binding ElementName=datePicker2, Path=CurrentlySelectedDate}"/>
			
		</StackPanel>

    </DockPanel>
</Window>
